package controller;

import Request.DispartIdRequest;
import com.alibaba.fastjson.JSON;
import modal.UserApplication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import service.AdminManageService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by tan on 2017/8/24.
 * 15:57
 */
@Controller
@RequestMapping(value = "/admin")
public class AdminController {

    @Autowired
    AdminManageService adminManageService;


    //获取用户提交的直播申请
    @RequestMapping("/getApplication.do")
    @ResponseBody
    public String getApplication(HttpServletRequest request, HttpServletResponse response)
    {
        response.setHeader("Cache-Control","no-cache");
        return JSON.toJSONString(adminManageService.getAllApplication());
    }

    //审批通过
    @RequestMapping("/allow.do")
    @ResponseBody
    public String allow(UserApplication application,HttpServletRequest request, HttpServletResponse response)
    {
        System.out.println(application);
        return adminManageService.allowApplication(application);
    }
    //审批不通过
    @RequestMapping("/refuse.do")
    @ResponseBody
    public String refuse(UserApplication application,HttpServletRequest request, HttpServletResponse response)
    {
        System.out.println(application);
        return adminManageService.refuseApplication(application);
    }

    //为用户分配ID
    @RequestMapping("/dispartId.do")
    @ResponseBody
    public String dispartId(DispartIdRequest dispartIdRequest ,
            HttpServletRequest request, HttpServletResponse response)
    {
        System.out.println(dispartIdRequest);
        response.setHeader("Cache-Control","no-cache");
        return adminManageService.giveID(dispartIdRequest);
    }
}
